package generics;

//: generics/FactoryConstraint.java

interface FactoryI<T> {
  T create(Object obj);
}

class Foo2<T> {
  private T x;
  public <F extends FactoryI<T>> Foo2(F factory, Object obj) {
    x = factory.create(obj);
  }
  public T getT(){
	  return x;
  }
  // ...
}

class IntegerFactory implements FactoryI<Integer> {
  public Integer create(Object obj) {
    return Integer.valueOf(obj.toString());
  }
}	

class Widget {
  public static class Factory implements FactoryI<Widget> {
    public Widget create(Object obj) {
      return new Widget();
    }
  }
}

public class FactoryConstraint {
  public static void main(String[] args) {
	Foo2<Integer> foo = new Foo2<Integer>(new IntegerFactory(), 1);
    new Foo2<Widget>(new Widget.Factory(), "str");
  }
} ///:~
